package com.lotea.android.andreaditlater.ui.widgets;

import java.util.Date;

import android.content.Context;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.lotea.android.andreaditlater.R;

public class ReadListItem extends RelativeLayout {

	private TextView title;
	private TextView url;
	private TextView tags;
	private TextView time;
	private ImageView favicon;
	private ImageView options;

	public ReadListItem(Context context) {
		super(context, null, 0);
	}

	public ReadListItem(Context context, AttributeSet attrs) {
		super(context, attrs, 0);
	}

	public ReadListItem(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
	}

	@Override
	protected void onFinishInflate() {
		super.onFinishInflate();

		time = (TextView) findViewById(R.id.time);
		title = (TextView) findViewById(R.id.title);
		url = (TextView) findViewById(R.id.url);
		tags = (TextView) findViewById(R.id.tags);
		favicon = (ImageView) findViewById(R.id.favicon);
		options = (ImageView) findViewById(R.id.actionButton);
	}

	public void setTitle(String text) {
		title.setText(text);
	}

	public void setUrl(String text) {
		url.setText(text);
	}

	public void setTags(String text) {
		tags.setText(text);
	}

	public void setTime(long millis) {
		Date date = new Date(millis * 1000);
		java.text.DateFormat timeFormat = android.text.format.DateFormat
				.getTimeFormat(getContext());
		time.setText(timeFormat.format(date));
	}
	
	public void markAsUnread() {
		title.setTypeface(Typeface.DEFAULT_BOLD);
		url.setTypeface(Typeface.DEFAULT_BOLD);
		setBackgroundResource(android.R.drawable.list_selector_background);
	}
	
	public void markAsRead() {
		title.setTypeface(Typeface.DEFAULT);
		url.setTypeface(Typeface.DEFAULT);
		setBackgroundResource(R.drawable.read_list_selector_background);
	}

	/* (non-Javadoc)
	 * @see android.view.View#setId(int)
	 */
	@Override
	public void setId(int id) {
		options.setTag(id);
		super.setId(id);
	}
}
